﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using Abp.Application.Services;
using Abp.AutoMapper;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.Web.Models;
using AbpDemo.Domain.Goods;
using AbpDemo.Goods.Dto;

namespace AbpDemo.Goods
{
    public class GoodsAppService : ApplicationService, IGoodsAppService
    {
        private readonly IRepository<Goods_1, Guid> _repo;

        public GoodsAppService(IRepository<Goods_1, Guid> repo) : base()
        {
            _repo = repo;
        }

        /// <summary>
        /// 获取全部goods内容
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        //[RemoteService(false)]
        [WrapResult(false)]
        public async Task<IList<GoodsDto>> GetAll()
        {
            return (await _repo.GetAllListAsync()).Select(g => g.MapTo<GoodsDto>()).ToList();
        }

        //TODO 读模型，注意实体的属性set
        [RemoteService(false)]
        [UnitOfWork(IsDisabled = true)]
        public async Task<Goods_1> GetById(Guid id)
        {
            return await _repo.GetAsync(id);
        }
    }
}
